package com.york.user.controller;


import com.york.bean.Result;
import com.york.page.PageResponse;
import com.york.user.convert.PageSysUserDtoConverter;
import com.york.user.convert.SysUserDtoConverter;
import com.york.user.entity.SysUser;
import com.york.user.entity.dto.PageSysUserDto;
import com.york.user.entity.dto.SysUserDto;
import com.york.user.entity.po.SysUserPo;
import com.york.user.entity.req.PageSysUserReq;
import com.york.user.entity.req.SysUserReq;
import com.york.user.service.SysUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * (SysUser)表控制层
 *
 * @author makejava
 * @since 2024-07-29 16:23:59
 */
@RestController
@RequestMapping("/sysUser")
@Api("SysUserController")
public class SysUserController {
    /**
     * 服务对象
     */
    @Resource
    private SysUserService sysUserService;


    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("/get/{id}")
    @ApiOperation(notes = "查询单条数据", value = "查询单条数据:/get/{id}")
    public Result<SysUserPo> queryById(@PathVariable("id") Long id) {
        return Result.ok(this.sysUserService.queryById(id));
    }

    /**
     * 分页查询
     *
     * @param pageSysUserReq 筛选条件
     * @return 查询结果
     */
    @GetMapping("/getPage")
    @ApiOperation(notes = "分页查询", value = "分页查询:/getPage")
    public Result<PageResponse<SysUserPo>> queryByPage(@RequestBody PageSysUserReq pageSysUserReq) {
        PageSysUserDto pageSysUserDto = PageSysUserDtoConverter.INSTANCE.convertReqToDto(pageSysUserReq);
        return Result.ok(this.sysUserService.queryByPage(pageSysUserDto));
    }

    /**
     * 新增数据
     *
     * @param sysUserReq 实体
     * @return 新增结果
     */
    @PostMapping("/add")
    @ApiOperation(notes = "新增数据", value = "新增数据:/add")
    public Result<SysUser> add(@RequestBody SysUserReq sysUserReq) {
        SysUserDto sysUserDto = SysUserDtoConverter.INSTANCE.convertReqToDto(sysUserReq);
        return Result.ok(this.sysUserService.insert(sysUserDto));
    }

    /**
     * 编辑数据
     *
     * @param sysUserReq 实体
     * @return 编辑结果
     */
    @PutMapping("/edit")
    @ApiOperation(notes = "编辑数据", value = "编辑数据:/edit")
    public Result<SysUser> edit(@RequestBody SysUserReq sysUserReq) {
        SysUserDto sysUserDto = SysUserDtoConverter.INSTANCE.convertReqToDto(sysUserReq);
        return Result.ok(this.sysUserService.update(sysUserDto));
    }

    /**
     * 物理删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @DeleteMapping("/delete/{id}")
    @ApiOperation(notes = "物理删除数据", value = "物理删除数据:/delete/{id}")
    public Result<Boolean> deleteById(@PathVariable("id") Long id) {
        return Result.ok(this.sysUserService.deleteById(id));
    }

    /**
     * 逻辑删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @DeleteMapping("/logicDelete/{id}")
    @ApiOperation(notes = "逻辑删除数据", value = "逻辑删除数据:/logicDelete/{id}")
    public Result logicDeleteById(@PathVariable Long id) {
        return Result.ok(this.sysUserService.logicDeleteById(id));
    }

}

